﻿
using System;

namespace FTP.Client.Common
{
    /// <summary>
    /// Base FTP exception class.
    /// </summary>
    public class FTPException : Exception
    {
        protected FTPException()
        {
        }

        public FTPException(string Message)
            : base(Message)
        {
        }

        public FTPException(string Message, Exception innerException)
            : base(Message, innerException)
        {
        }
    }

    public class FTPReplyParseException : FTPException
    {
        private string replyText;

        public string ReplyText
        {
            get { return replyText; }
        }

        public FTPReplyParseException(string replyText)
            : base("Invalid server reply: " + replyText)
        {
            this.replyText = replyText;
        }
    }

    public class FTPProtocolException : FTPException
    {
        FTPReply reply;

        public FTPReply Reply
        {
            get { return reply; }
        }

        public FTPProtocolException(FTPReply reply) : base("Invalid FTP protocol reply: " + reply.ToString())
        {
            this.reply = reply;
        }
    }

    /// <summary>
    /// Exception indicating that a command or set of commands have been cancelled by the caller, via a callback method or event.
    /// </summary>
    public class FTPOperationCancelledException : FTPException
    {
        public FTPOperationCancelledException(string Message)
            : base(Message)
        {
        }
    }

    /// <summary>
    /// FTP exception generated by a command with a return code >= 400, as stated in RFC 959.
    /// </summary>
    public class FTPCommandException : FTPException
    {
        int errorCode;

        public int ErrorCode
        {
            get { return errorCode; }
        }

        public FTPCommandException(string Message)
            : base(Message)
        {
        }

        public FTPCommandException(string Message, Exception innerException)
            : base(Message, innerException)
        {
        }

        public FTPCommandException(FTPReply reply)
            : base(reply.Message)
        {
            this.errorCode = reply.Code;
        }
    }

    /// <summary>
    /// FTP exception related to the SSL/TLS support
    /// </summary>
    public class FTPSslException : FTPException
    {
        public FTPSslException(string Message)
            : base(Message)
        {
        }

        public FTPSslException(string Message, Exception innerException)
            : base(Message, innerException)
        {
        }
    }
}
